package com.ysqcould.web.controller.allocation;


import com.ysqcould.allocation.domain.Dues;
import com.ysqcould.allocation.domain.Poster;
import com.ysqcould.allocation.service.IPosterService;
import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 海报模板地址Controller
 * 
 * @author ruoyi
 * @date 2022-06-29
 */
@RestController
@RequestMapping("/allocation/poster")
public class PosterController extends BaseController
{
    @Autowired
    private IPosterService posterService;

    /**
     * 查询海报模板地址列表
     */
    @PreAuthorize("@ss.hasPermi('allocation:poster:list')")
    @GetMapping("/list")
    public TableDataInfo list(Poster poster)
    {
        startPage();
        List<Poster> list = posterService.selectPosterList(poster);
        return getDataTable(list);
    }

    /**
     * 导出海报模板地址列表
     */
    @PreAuthorize("@ss.hasPermi('allocation:poster:export')")
    @Log(title = "海报模板地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Poster poster)
    {
        List<Poster> list = posterService.selectPosterList(poster);
        ExcelUtil<Poster> util = new ExcelUtil<Poster>(Poster.class);
        util.exportExcel(response, list, "海报模板地址数据");
    }

    /**
     * 获取海报模板地址详细信息
     */
    @PreAuthorize("@ss.hasPermi('allocation:poster:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(posterService.selectPosterById(id));
    }

    /**
     * 新增海报模板地址
     */
    @PreAuthorize("@ss.hasPermi('allocation:poster:add')")
    @Log(title = "海报模板地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Poster poster)
    {
        poster.setAsId(getUserId());
        return toAjax(posterService.insertPoster(poster));
    }

    /**
     * 修改海报模板地址
     */
    @PreAuthorize("@ss.hasPermi('allocation:poster:edit')")
    @Log(title = "海报模板地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Poster poster)
    {
        return toAjax(posterService.updatePoster(poster));
    }

    /**
     * 删除海报模板地址
     */
    @PreAuthorize("@ss.hasPermi('allocation:poster:remove')")
    @Log(title = "海报模板地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(posterService.deletePosterByIds(ids));
    }

    /**
     * 状态修改
     */
    @Log(title = "通信录", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody Poster ps)
    {
        return toAjax(posterService.updateStatus(ps));
    }
}
